package com.ruoyi.web.controller.combat.antihoming;

import com.ruoyi.combat.domain.neo4j.CombatAtlasTask;
import com.ruoyi.combat.domain.neo4j.IpNode;
import com.ruoyi.combat.domain.request.AntiHomingInfoRequest;
import com.ruoyi.combat.service.antihoming.AntiHomingInfoService;
import com.ruoyi.combat.service.antihoming.CombatAtlasTaskService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 网络IPController
 *
 * @author ruoyi
 * @date 2025-01-06
 */
@Api(tags = "课题四：网络目标IP归属保护-图谱展示")
@RestController
@RequestMapping("/antiHoming/info")
public class AntiHomingInfoController extends BaseController {

    @Autowired
    private AntiHomingInfoService antiHomingInfoService;
    @Autowired
    private CombatAtlasTaskService combatAtlasTaskService;

    @ApiOperation(value = "查询网络IP列表")
    @RequestMapping("/list")
    public AjaxResult list(@RequestBody AntiHomingInfoRequest request) {
        Page<IpNode> ipNodes = antiHomingInfoService.antiHomingInfoByIpOrOrg(request);
        return success(ipNodes);
    }

    /**
     * 确定风险页数据查询
     */
    @ApiOperation(value = "确定风险页数据查询")
    @PostMapping("/riskPageQuery")
    public AjaxResult riskPageQuery(@RequestBody AntiHomingInfoRequest request) {
        return success(antiHomingInfoService.riskPageQuery(request));
    }

    /**
     * 抗归属任务新增
     */
    @ApiOperation(value = "抗归属任务新增")
    @PostMapping("/addCombatAtlasTask")
    public AjaxResult addCombatAtlasTask(@RequestBody CombatAtlasTask task) {
        return success(combatAtlasTaskService.insertCombatAtlasTask(task));
    }

    /**
     * 分页查询抗归属任务
     */
    @ApiOperation(value = "分页查询抗归属任务")
    @PostMapping("/selectCombatAtlasTaskList")
    public AjaxResult selectCombatAtlasTaskList(@RequestBody AntiHomingInfoRequest request) {
        return success(combatAtlasTaskService.selectCombatAtlasTaskList(request));
    }

    /**
     * 根据id 删除抗归属任务
     */
    @ApiOperation(value = "根据id 删除抗归属任务")
    @GetMapping("/deleteCombatAtlasTaskById/{id}")
    public AjaxResult deleteCombatAtlasTaskById(@PathVariable Long id) {
        combatAtlasTaskService.deleteCombatAtlasTaskById(id);
        return success();
    }

    /**
     * 查询预测组织和节点的关系
     */
    @ApiOperation(value = "分页查询预测组织和节点的关系")
    @PostMapping("/predictRelationship")
    public AjaxResult predictRelationship(@RequestBody AntiHomingInfoRequest request) {
        return success(antiHomingInfoService.predictRelationship(request));
    }

    /**
     * IP-组织关系确定的抗归属
     */
    @ApiOperation(value = "IP-组织关系确定的抗归属")
    @PostMapping("/antiHomingInfo")
    public AjaxResult antiHomingInfo(@RequestBody AntiHomingInfoRequest request) {
        antiHomingInfoService.antiHomingInfo(request);
        return success();
    }

    /**
     * 预测IP-组织归属关系抗归属
     */
    @ApiOperation(value = "预测IP-组织归属关系抗归属")
    @PostMapping("/predictAntiHomingInfo")
    public AjaxResult predictAntiHomingInfo(@RequestBody AntiHomingInfoRequest request) {
        return success(antiHomingInfoService.predictAntiHomingInfo(request));
    }

    /**
     * 终止抗归属任务
     */
    @ApiOperation(value = "终止抗归属任务")
    @GetMapping("/stopCombatAtlasTask/{id}")
    public AjaxResult stopCombatAtlasTask(@PathVariable Long id) {
        combatAtlasTaskService.stopCombatAtlasTask(id);
        return success();
    }

    /**
     * 根据Id查询抗归属任务详情
     */
    @ApiOperation(value = "根据Id查询抗归属任务详情")
    @GetMapping("/selectCombatAtlasTaskById/{id}")
    public AjaxResult selectCombatAtlasTaskById(@PathVariable Long id) {
        return success(combatAtlasTaskService.selectCombatAtlasTaskById(id));
    }

    /**
     * 归属风险统计
     */
    @ApiOperation(value = "归属风险统计")
    @GetMapping("/riskStatistics")
    public AjaxResult riskStatistics() {
        return success(antiHomingInfoService.riskStatistics());
    }

    /**
     * 查询所有组织
     */
    @ApiOperation(value = "查询所有组织")
    @GetMapping("/getAllOrg")
    public AjaxResult getAllOrg() {
        return success(antiHomingInfoService.getAllOrg());
    }

    /**
     * 抗归属任务
     */
    @PostMapping("/combatAtlasTask")
    public AjaxResult combatAtlasTask(@RequestBody Map map) {
        antiHomingInfoService.combatAtlasTask( map);
        return success();
    }

    @Anonymous
    @GetMapping("/getInfoByIp")
    public AjaxResult getInfoByIp(@RequestParam("ip") String ip,@RequestParam("type") String type) {
        return success(antiHomingInfoService.getInfoByIp(ip, type));
    }

    @ApiOperation(value = "大屏默认图谱")
    @GetMapping("/screen")
    public AjaxResult screen() {
        return success(antiHomingInfoService.screen());
    }
}
